<script setup>
import {Notification} from "@arco-design/web-vue";
import {ref} from 'vue';
import apiAll from "@/api/apiAll.js";
import Bus from "@/utils/bus";

const emits = defineEmits(["success"]);
const visible = ref(false);
const form = ref({});
const handleOk = (done) => {
  if (!form.value.password) {
    Notification.warning('登录密码不能为空')
    done(false)
    return;
  }
  Bus.emit('loading', true)
  apiAll.accessLogApi.clearAllData(form.value.password).then(res => {
    Notification.success(res.msg)
    visible.value = true
    setTimeout(() => {
      emits("success")
      done()
    }, 300)
  }).catch(() => {
    setTimeout(() => {
      done(false)
    }, 300)
  }).finally(() => {
    setTimeout(() => {
      Bus.emit('loading', false)
    }, 500)
  })
};
const handleCancel = () => {
  visible.value = false;
}

const show = () => {
  visible.value = true;
}

defineExpose({show});
</script>

<template>
  <a-modal width="300" v-model:visible="visible" title="清理所有数据" @cancel="handleCancel" @before-ok="handleOk">
    <a-form :model="form">
      <a-form-item field="name" label="登录密码">
        <a-input-password v-model="form.password" placeholder="请输入登录密码"/>
      </a-form-item>
      <a-form-item field="name" label="提示">
        <b style="color: red">此操作将会清空访问日志，<br/>并备份到 back/access_log_(时间戳).txt</b>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<style scoped>

</style>